package qlsl.androiddesign.http.service.subservice;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.otherentity.RecruitJob;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.view.baseview.FunctionView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * 招聘详情模块 <br/>
 * 
 */
public class RecruitDetailService extends BaseService {

	private static String className = getClassName(RecruitDetailService.class);

	/**
	 * 获取招聘评论列表
	 * 
	 * @param recruitJob
	 * @param functionView
	 * @param listener
	 */
	public static void queryRecruitDetailList(final RecruitJob recruitJob,
			final FunctionView<?> functionView, final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener,
				className, "queryRecruitDetailList");
		new HandlerThread(className, "queryRecruitDetailList") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();
				try {
					JSONObject jo = protocol
							.setMethod("getadvertisescommentlist")
							.addParam("advertisesid",
									recruitJob.getAdvertisesid()).post();

					if (isDataInvalid(jo, handler, protocol)) {
						return;
					}

					JSONObject jo_old = (JSONObject) JSON.toJSON(recruitJob);
					JSONObject jo_parent = new JSONObject();
					jo_parent.putAll(jo_old);
					jo_parent.putAll(jo);

					RecruitJob object = JSON.toJavaObject(jo_parent,
							RecruitJob.class);

					handler.sendMessage(protocol,
							WhatConstant.WHAT_NET_DATA_SUCCESS, object);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON,
							e);
				}
			};
		}.start();
	}
}
